package com.proxyadvertise.parse;

import com.ice.jni.registry.RegDWordValue;
import com.ice.jni.registry.RegStringValue;
import com.ice.jni.registry.Registry;
import com.ice.jni.registry.RegistryKey;

public class RegistryManager {

	public static void setProxyIp(String ip ) throws Exception {
		
		RegistryKey registryKey = Registry
				.openSubkey(
						Registry.HKEY_CURRENT_USER,
						"Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings",
						RegistryKey.ACCESS_ALL);
		
		RegStringValue proxyServer = new RegStringValue(registryKey, "ProxyServer");
		proxyServer.setData( ip );
		registryKey.setValue( proxyServer );
		
		RegDWordValue proxyEnable = new RegDWordValue( registryKey , "ProxyEnable" );
		proxyEnable.setData( 1 );
		registryKey.setValue( proxyEnable );
		
	}
	
	public static void clearProxy() throws Exception{
		
		RegistryKey registryKey = Registry
		.openSubkey(
				Registry.HKEY_CURRENT_USER,
				"Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings",
				RegistryKey.ACCESS_ALL);
		
		RegDWordValue proxyEnable = new RegDWordValue( registryKey , "ProxyEnable" );
		proxyEnable.setData( 0 );
		registryKey.setValue( proxyEnable );
		
	}
	
	public static void main(String[] args) throws Exception {
		RegistryManager.clearProxy();
//		ProxyIp.parse();
//		RegistryManager.setProxyIp( ProxyIp.getAllProxyIp().get( 0 ) );
	}
}
